home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Mac OS X Throbber / Source / Utilities / UMiscUtils.h < prev   
Encoding:
Text File  |  2000-06-24  |  2.4 KB  |  106 lines

  1. // ===========================================================================
  2. //    UMiscUtils.h            ©1997-1999 Metrowerks Inc. All rights reserved.
  3. //    Original Author: John C. Daub
  4. // ===========================================================================
  5.  
  6. #ifndef _H_UMiscUtils
  7. #define _H_UMiscUtils
  8. #pragma once
  9.  
  10. #include <PP_Prefix.h>
  11.  
  12. #if PP_Uses_Pragma_Import
  13.     #pragma import on
  14. #endif
  15.  
  16. namespace UMiscUtils {
  17.  
  18.     bool                System7Present();
  19.  
  20.     bool                TrapAvailable(
  21.                                 SInt16                inTrap);
  22.     TrapType            GetTrapType(
  23.                                 SInt16                inTrap);
  24.     SInt16                NumToolboxTraps();
  25.         
  26.     bool                MemoryIsLow();
  27.         
  28.     bool                IsFontInstalled(
  29.                                 ConstStr255Param    inName);    
  30. }
  31.  
  32.  
  33. // ===========================================================================
  34. //    • StCriticalSection
  35. // ===========================================================================
  36. //    StCriticalSection is a stack-based object that marks a "critical section,"
  37. //    i.e. a section that should not be allowed to fail because memory is
  38. //    running low. Examples of appropriate uses of StCriticalSection are
  39. //    commands that close windows or save files.
  40.  
  41. class StCriticalSection {
  42.  
  43. public:
  44.                         StCriticalSection()
  45.                             {
  46.                                 mWasInCriticalSection    = sCriticalSection;
  47.                                 sCriticalSection        = true;
  48.                             }
  49.                                 
  50.     virtual                ~StCriticalSection()
  51.                             {
  52.                                 sCriticalSection = mWasInCriticalSection;
  53.                             }
  54.  
  55.     static    bool        InCriticalSection()
  56.                             {
  57.                                 return sCriticalSection;
  58.                             }
  59.     
  60.  
  61. private:
  62.  
  63.             bool        mWasInCriticalSection;
  64.     static    bool        sCriticalSection;
  65. };
  66.  
  67.  
  68. // ===========================================================================
  69. //    • StInterruptSection
  70. // ===========================================================================
  71. //    StInterruptSection is a stack-based object that marks an "interrupt
  72. //    section," i.e. a section of code that (could) execute at interrupt time.
  73. //    Useful in memory allocation to prohibit allocation at interrupt time.
  74.  
  75. class StInterruptSection {
  76.  
  77. public:
  78.                         StInterruptSection()
  79.                             {
  80.                                 mWasInInterruptSection    = sInterruptSection;
  81.                                 sInterruptSection        = true;
  82.                             }
  83.                         
  84.     virtual                ~StInterruptSection()
  85.                             {
  86.                                 sInterruptSection = mWasInInterruptSection;
  87.                             }
  88.  
  89.     static    bool        InInterruptSection()
  90.                             {
  91.                                 return sInterruptSection;
  92.                             }
  93.     
  94.  
  95. private:
  96.             bool        mWasInInterruptSection;
  97.     static    bool        sInterruptSection;
  98.  
  99. };
  100.  
  101.  
  102. #if PP_Uses_Pragma_Import
  103.     #pragma import reset
  104. #endif
  105.  
  106. #endif // _H_UMiscUtils